import { CommonQueryParams, POST, Auth, QueryParams, ResponeList, PUT, GET, OptRespone } from 'spd-request';

export interface IGetRolesParams extends Partial<CommonQueryParams> {

}
export interface RoleStruct {
    creationTime: string;
    creationUniversalTime: number;
    description: string;
    displayName: string;
    id: number;
    isDefault: boolean;
    isStatic: boolean;
    name: string;
}
export namespace RoleRequest {

    export function getRoles(params: IGetRolesParams = {}): Promise<OptRespone<ResponeList<RoleStruct>>> {
        let newParam = Object.assign({page: 1, pageSize: 10}, params?params:{});
        return GET('/Role/GetRoles', {params: newParam})
        .then(res => {
            if(res.success === true) {
                return {error: null, data: res.result}
            } else {
                return {error: '获取角色列表失败！', data: {totalCount: 0, items: []}}
            }
        })
        .catch(() => {
            return {error: '获取角色列表失败！', data: {totalCount: 0, items: []}}
        })
    }
}